//
//  AnimationIndicator.m
//  jipin
//
//  Created by lcb on 6/10/15.
//  Copyright (c) 2015 liuchengbin. All rights reserved.
//

#import "AnimationIndicator.h"
#import "ZShare.h"
@implementation AnimationIndicator

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor clearColor];
        _isAnimating = NO;
        imageView = [[UIImageView alloc] initWithFrame:CGRectMake((frame.size.width-60)/2,0, 60,60)];
        [self addSubview:imageView];
        //设置动画帧
        imageView.animationImages=[NSArray arrayWithObjects: [UIImage imageNamed:@"refresh01"],
                                   [UIImage imageNamed:@"refresh02"],
                                   [UIImage imageNamed:@"refresh03"],
                                   nil ];
        
        
        Infolabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 60, frame.size.width, 20)];
        Infolabel.backgroundColor = [UIColor clearColor];
        Infolabel.textAlignment = NSTextAlignmentCenter;
        Infolabel.textColor = [UIColor grayColor];
        Infolabel.font = [UIFont systemFontOfSize:11];
        [self addSubview:Infolabel];
        self.layer.hidden = YES;
    }
    return self;
}


- (void)startAnimation
{
    _isAnimating = YES;
    self.layer.hidden = NO;
    [self doAnimation];
}
- (void)stopAnimation
{
    [imageView stopAnimating];
    self.layer.hidden = YES;
    self.alpha = 1;
}
-(void)doAnimation{
    Infolabel.text = _loadtext;
    //设置动画总时间
    imageView.animationDuration=0.6;
    //设置重复次数,0表示不重复
    imageView.animationRepeatCount=0;
    //开始动画
    [imageView startAnimating];
}

- (void)stopAnimationWithLoadText:(NSString *)text withType:(BOOL)type;
{
    _isAnimating = NO;
    Infolabel.text = text;
    if(type){
        
        [UIView animateWithDuration:0.3f animations:^{
            self.alpha = 0;
        } completion:^(BOOL finished) {
            [imageView stopAnimating];
            self.layer.hidden = YES;
            self.alpha = 1;
        }];
    }else{
        [imageView stopAnimating];
        [imageView setImage:[UIImage imageNamed:@"refresh03"]];
    }
    
}


-(void)setLoadText:(NSString *)text;
{
    if(text){
        _loadtext = text;
    }
}


@end
